<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>samphold</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="s32b14.html" title="s32b14" />
    <link rel="next" href="sandpaper.html" title="sandpaper" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">samphold</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="s32b14.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="sandpaper.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="samphold"></a>
      <div class="titlepage"></div>
      <a id="IndexSamphold" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">samphold</span>
        </h2>
        <p>samphold — 
      Performs a sample-and-hold operation on its input.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp143721488"></a>
        <h2>Description</h2>
        <p>
      Performs a sample-and-hold operation on its input.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp143794656"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>samphold</strong></span> asig, agate [, ival] [, ivstor]</pre>
        <pre class="synopsis">kres <span class="command"><strong>samphold</strong></span> ksig, kgate [, ival] [, ivstor]</pre>
      </div>
      <div class="refsect1">
        <a id="idp143798304"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>ival, ivstor</em></span> (optional) -- controls initial disposition of internal save space. If <span class="emphasis"><em>ivstor</em></span> is zero the internal <span class="quote">“<span class="quote">hold</span>”</span> value is set to <span class="emphasis"><em>ival</em></span> ; else it retains its previous value. Defaults are 0,0 (i.e. init to zero)
    </p>
      </div>
      <div class="refsect1">
        <a id="idp143801392"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>kgate, xgate</em></span> -- controls whether to hold the signal.
    </p>
        <p>
      <span class="emphasis"><em>samphold</em></span> performs a sample-and-hold operation on its input according to the value of <span class="emphasis"><em>gate</em></span>. If <span class="emphasis"><em>gate != 0</em></span>, the input samples are passed to the output; if <span class="emphasis"><em>gate = 0</em></span>, the last output value is repeated. The controlling <span class="emphasis"><em>gate</em></span> can be a constant, a control signal, or an audio signal.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp143805856"></a>
        <h2>Examples</h2>
        <p>
      </p>
        <div class="informalexample">
          <pre class="programlisting">
asrc  <span class="opc">buzz</span>      10000, 440, 20, 1     <span class="comment">; band-limited pulse train</span>
adif  <span class="opc">diff</span>      asrc                  <span class="comment">; emphasize the highs</span>
anew  <span class="opc">balance</span>   adif, asrc            <span class="comment">;   but retain the power</span>
agate <span class="opc">reson</span>     asrc, 0, 440          <span class="comment">; use a lowpass of the original</span>
asamp <span class="opc">samphold</span>  anew, agate           <span class="comment">;   to gate the new audiosig</span>
aout  <span class="opc">tone</span>      asamp, 100            <span class="comment">; smooth out the rough edges</span></pre>
        </div>
        <p>
    </p>
        <p>
      Here is another example of the samphold opcode. It uses the file <a class="ulink" href="examples/samphold.csd" target="_top"><em class="citetitle">samphold.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp143817648"></a>
          <p class="title">
            <strong>Example 777. Example of the samphold opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o samphold.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1

kx	<span class="opc">line</span> <span class="op">-</span>1, p3, 1   	<span class="comment">; between -1 and +1 </span>
ktrig	<span class="opc">metro</span> 1	 		<span class="comment">; triggers 1 time per second </span>
kval	<span class="opc">samphold</span> kx, ktrig	<span class="comment">; change value whenever ktrig = 1 </span>
        <span class="opc">printk2</span> kval		<span class="comment">; will print every time kval changes </span>
asig	<span class="opc">diskin2</span>	"flute.aiff", 1<span class="op">+</span>kval, 0, 1
	<span class="opc">outs</span> asig, asig

<span class="oblock">endin</span> 
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
 

<span class="stamnt">i</span> 1 0 11 
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp143821936"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="diff.html" title="diff"><em class="citetitle">diff</em></a>,
      <a class="link" href="downsamp.html" title="downsamp"><em class="citetitle">downsamp</em></a>,
      <a class="link" href="integ.html" title="integ"><em class="citetitle">integ</em></a>,
      <a class="link" href="interp.html" title="interp"><em class="citetitle">interp</em></a>,
      <a class="link" href="upsamp.html" title="upsamp"><em class="citetitle">upsamp</em></a>
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="s32b14.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="sandpaper.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">s32b14 </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> sandpaper</td>
        </tr>
      </table>
    </div>
  </body>
</html>
